package com.scwatch.core.domain;

import com.scwatch.core.support.Siteable;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.*;
import java.util.Date;

/**
 * Created by rh005 on 2017/7/17.
 */
@Entity
@Table(name = "cms_sinatv")
public class Sinatv implements java.io.Serializable,Siteable {
    private static final long serialVersionUID = 1L;
    /**
     * ����
     */
    public static final int NORMAL = 0;
    /**
     * ����
     */
    public static final int DISABLED = 1;

    @Transient
    public void applyDefaultValue() {
        if (getStatus() == null) {
            setStatus(NORMAL);
        }
    }

    private Integer id;
    private String name;
    private String replacement;
    private Integer status;
    private User user;
    private Date time;
    private String address;
    private String logoImg;     //卫视logo图片
    private String audioUrl; //音频流
    private String audioImg; //音频封面图片
    private String programmes;
    private String excelUrl;
    @Transient
    private String programmesJsonUrl; //节目单内容jsonurl，非数据库字段
    /**
     * վ��
     */
    private Site site;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "f_site_id", nullable = false)
    public Site getSite() {
        return site;
    }

    public void setSite(Site site) {
        this.site = site;
    }

    @Id
    @Column(name = "f_hotword_id", unique = true, nullable = false)
    @TableGenerator(name = "tg_cms_hot_word", pkColumnValue = "cms_hot_word", initialValue = 1, allocationSize = 10)
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "tg_cms_hot_word")
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name = "f_name", nullable = false, length = 100)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "f_replacement", length = 100)
    public String getReplacement() {
        return this.replacement;
    }

    public void setReplacement(String replacement) {
        this.replacement = replacement;
    }

    @Column(name = "f_status", nullable = false)
    public Integer getStatus() {
        return this.status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "f_user_id", nullable = false)
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "f_time", nullable = false, length = 19)
    public Date getTime() {
        return this.time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    @Column(name = "f_broadcast_address", length = 200)
    public String getAddress() {return this.address;}

    public void setAddress(String address) {
        this.address = address;
    }

    @Column(name = "f_audio_url", length = 100)
    public String getAudioUrl() {
        return audioUrl;
    }

    public void setAudioUrl(String audioUrl) {
        this.audioUrl = audioUrl;
    }

    @Column(name = "f_audio_img",length = 100)
    public String getAudioImg() {
        return audioImg;
    }

    public void setAudioImg(String audioImg) {
        this.audioImg = audioImg;
    }

    @Column(name = "f_programmes")
    public String getProgrammes() {return programmes;}

    public void setProgrammes(String programmes) {this.programmes = programmes;}

    @Column(name = "f_programmes_excelurl", length = 100)
    public String getExcelUrl() {return excelUrl;}

    public void setExcelUrl(String excelUrl) {this.excelUrl = excelUrl;}

    @Column(name = "f_logo_img",length = 100)
    public String getLogoImg() {
        return logoImg;
    }

    public void setLogoImg(String logoImg) {
        this.logoImg = logoImg;
    }

    @Transient
    public String getProgrammesJsonUrl() {
        return programmesJsonUrl;
    }

    public void setProgrammesJsonUrl(String programmesJsonUrl) {
        this.programmesJsonUrl = programmesJsonUrl;
    }

    @Transient
    public String getTvType() {
       String type="1"; //默认视频播放
       if(StringUtils.isNotBlank(audioUrl)){
          type="2";
       }
       return  type;
    }
}
